package rtos;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.catalina.filters.RequestDumperFilter;

@WebServlet("/surveycalcurator")
public class SurveyCalcurator extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public SurveyCalcurator() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doPost(request,response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("SurveyCalcuratorIndex");
		String data = request.getParameter("choice");
		System.out.println(data);
		ArrayList<TypeValue> tvArr = new ArrayList<TypeValue>();
		TypeValue tv=null;
		int size = data.split("@").length;
		System.out.println("size : "+size);
		for(int i=0;i<size;i++){
			String type = data.split("@")[i].split("-")[0];
			String value = data.split("@")[i].split("-")[1];
			System.out.println("type : "+type+" --- value : "+value);
			tv = new TypeValue(type, value);
			tvArr.add(tv);
		}
		
		request.setAttribute("tvArr", tvArr);
		RequestDispatcher dispatcher = request.getRequestDispatcher("/graph.jsp");
		dispatcher.forward(request, response);
	}
}


